<?php
use App\Models\Topic;
use Illuminate\Support\Facades\Auth;

return [
    'title' => '帖子',
    'single' => '帖子',
    'model' => Topic::class,

    'action_permissions' => [
        'delete' => function ($model) {
            return Auth::user()->hasRole('Founder');
        },


    ],
    'columns' => [
        'id' => [
            'title' => 'ID'
        ],
        'title' => [
            'title' => '帖子',
            'sortable' => false,
            'output'=>function($name,$model){
                return '<div style="max-width:240px;">'.model_link($name,$model).'</div>';
            },
        ],
        'user' => [
            'title' => '作者',
            'sortable' => false,
            'output'=>function($name,$model){
               $avatar = $model->user->avatar;
               $value = empty($avatar) ? 'N/A' : '<img src="'.$avatar.'" width=50 class="img-thumbnail" />'.$model->user->name;
               return model_link($value,$model);
            },
        ],
        'category' => [
            'title' => '分类',
            'sortable' => false,
            'output'=>function($name,$model){
               return model_admin_link($model->category->name,$model->category);
            },
        ],
        'reply_count' => [
            'title' => '评论'
        ],
        'operation'=>[
            'title'=>'管理',
            'sortable'=>false,
        ]
    ],
    'edit_fields' => [
        'title' => [
            'title' => '标题',
        ],
        'user' => [
            'title' => '用户',
            'type'=>'relationship',
            'name_field'=>'name',
            'autocomplete'=>true,
            'search_fields'=>["CONCAT(id,' ',name)"],
            'options_sort_field'=>'id'
        ],
        'category' => [
            'title' => '分类',
            'type'=>'relationship',
            'name_field'=>'name',
            'autocomplete'=>true,
            'search_fields'=>["CONCAT(id,' ',name)"],
            'options_sort_field'=>'id'
        ],

    ],
    'filters' => [
        'id' => [
            'title' => 'ID'
        ],
        'user' => [
            'title' => '用户',
            'type'=>'relationship',
            'name_field'=>'name',
            'autocomplete'=>true,
            'search_fields'=>["CONCAT(id,' ',name)"],
            'options_sort_field'=>'id'
        ],
        'category' => [
            'title' => '分类',
            'type'=>'relationship',
            'name_field'=>'name',
            'autocomplete'=>true,
            'search_fields'=>["CONCAT(id,' ',name)"],
            'options_sort_field'=>'id'
        ],
     ],
    'rules'=>[
        'title'=>'required'
    ],
    'messages'=>[
        'title.required'=>'帖子标题不能为空',
    ],

];
